package com.tom.org.service.impl;

import com.tom.basic.utils.PageList;
import com.tom.org.domain.Department;
import com.tom.org.mapper.DepartmentMapper;
import com.tom.org.query.DepartmentQuery;
import com.tom.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class IDepartmentServiceImpl implements IDepartmentService {
   @Autowired
   private DepartmentMapper departmentMapper;

    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }
    @Transactional
    @Override
    public void remove(Long id) {
         departmentMapper.remove(id);
    }

    @Transactional
    @Override
    public void save(Department department) {
     departmentMapper.save(department);
    }
    @Transactional
    @Override
    public void update(Department department) {
     departmentMapper.update(department);
    }

    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
     // 查询当前页数据
     List<Department> rows = departmentMapper.queryData(departmentQuery);
    
     // 查询总条数
     Integer total = departmentMapper.queryCount(departmentQuery);

     return new PageList<>(total,rows);
    }
}
